/*
 * URLConnection.h
 *
 *  Created on: 2010-6-19
 *      Author: guobc
 */

#ifndef URLCONNECTION_H_
#define URLCONNECTION_H_

#include <fstream>
#include <cstdio>
#include <iostream>
#include <cstring>
#include "URL.h"
#include "Socket.h"

using namespace std;

namespace HA {

class URLConnection {
public:

	/**
	 *Create a URL connection with given URL.
	 *@param URL The specified URL.
	 */
	URLConnection(URL url) :
		contentLength(""), contentType(""), encoding(""), mUrl(url), expir(-1),
				date(-1), connected(false), m_socket() {

	}

	/**
	 * Open a connections link to the resource referenced by this URL.
	 */
	int connect();

	void close();

	/**
	 * download the HTML document's string from the HTML server and store in the 'content'
	 *
	 */
	void download(string& content);

	int getContentLength();

	string getContentType();

	string getContentEncoding();

	unsigned long getExpiration();

	unsigned long getDate();

	~URLConnection() {
	}

protected:
	void sendRequests();
	//	bool checkStop(const char* buffer);
private:
	string contentLength;
	string contentType;
	string encoding;
	URL mUrl;
	unsigned long expir;
	unsigned long date;
	bool connected;
	Socket m_socket;
};

}

#endif /* URLCONNECTION_H_ */
